package drawer2.figure;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import drawer2.figure.Ellipse;
import drawer2.figure.Rect;
import drawer2.figure.Square;

public class  CanvasEditor implements ActionListener, MouseListener
{
        private JButton currentButton;
	private Figure currentFigure;
        public CanvasEditor(JButton initialSelectedButton)
        {
                this.currentButton = initialSelectedButton;
        }
        public void actionPerformed(ActionEvent e)
        {
		JButton currentButton = (JButton) e.getSource();
                //currentButton = (JButton) e.getSource();
		if(currentButton.getText().equals("Ellipse"))
		{
			currentFigure = new Ellipse(0,0,60,40);
		}
		else if(currentButton.getText().equals("Rect"))
		{
			currentFigure = new Rect(0,0,60,40);
		}
		else
		{
			currentFigure = new Square(0,0,50);
		}
        }
        public void mouseClicked(MouseEvent e)
        {
		//JPanel canvas = (JPanel) e.getSource();
		//currentFigure.setCenter(e.getX(),e.getY());
		//currentFigure.draw(canvas.getGraphics());
                int x = e.getX();
                int y = e.getY();
                JPanel canvas = (JPanel) e.getSource();
                if(currentButton.getText().equals("Ellipse"))
                {
                        canvas.getGraphics().drawOval(x-30,y-20,60,40);
                }
                else if(currentButton.getText().equals("Rect"))
                {
                        canvas.getGraphics().drawRect(x-30,y-20,60,40);
                }
                else
                {
                        canvas.getGraphics().drawRect(x-25,y-25,50,50);
                }
        }
        public void mousePressed(MouseEvent e){}
        public void mouseReleased(MouseEvent e){}
        public void mouseEntered(MouseEvent e){}
        public void mouseExited(MouseEvent e){}
}


